package com.baigt.juc.base;

/**
 * 类功能描述:
 * 线程优先级
 * 优先级的级数有多少？
 * 有什么规则？
 *
 * @author baigt
 * @version V1.0
 * @since 2019-10-21 10:25
 */
public class ThreadRun03 {
    public static void main(String[] args) {
        priority3();
    }

    public static void priority1() {
        //  这个线程的优先级是多少？
        Thread t = new Thread("ricky") {
            @Override
            public void run() {

            }
        };
        t.setPriority(10);
        t.start();
        System.out.println(t.getPriority());

    }

    public static void priority2() {
        ThreadGroup g = new ThreadGroup("ricky");
        g.setMaxPriority(7);
        //  这个线程的优先级是多少？
        Thread t = new Thread(g, "ricky") {
            @Override
            public void run() {

            }
        };
        t.setPriority(10);
        t.start();
        System.out.println(t.getPriority());
    }

    public static void priority3() {
        ThreadGroup g = new ThreadGroup("ricky");
        g.setMaxPriority(7);
        //  这个线程的优先级是多少？
        Thread t = new Thread(g, "ricky") {
            @Override
            public void run() {
                Thread inner = new Thread(g, "rickyInner") {
                    @Override
                    public void run() {
                        System.out.println("inner priority is " + Thread.currentThread().getPriority());
                    }
                };
                                inner.setPriority(10);
                inner.start();

            }
        };
        t.start();
    }
}
